<?php
require_once ("../db/connectdatabase.php");

function getTypeNews() {
	$con = new ConnectDB();
	
	$tbl = "typenews";
	$fn = array('idtnew', 'nametypenew', 'datecreate');
	$condetion = array('isuse' => 1);
	return $con -> getvalue($tbl, $fn, $condetion);
}

function deleteTypeNew($id, $ht) {
	$con = new ConnectDB();
	
	$tbl = "typenews";
	$fn = array('isuse' => $ht);
	$condition = array('idtnew' => $id);
	return $con -> update($tbl, $fn, $condition);
}

function removeTypeNew($id) {
	$con = new ConnectDB();
	$tbl = "typenews";
	$condition = array('idtnew' => $id);
	return $con -> delete($tbl, $condition);
}

$action = $_POST['act'];
if($action == 'del') {
	$result = false;
	if(isset($_POST['idre'])) {
		$id = $_POST['idre'];
		if(deleteTypeNew($id, 0)) {
			$result = true;
		}
	}
	echo json_encode($result);
} else if($action == 'undel') {
	$result = false;
	if(isset($_POST['idre'])) {
		$id = $_POST['idre'];
		if(deleteTypeNew($id, 1)) {
			$result = true;
		}
	}
	echo json_encode($result);
} else if($action == "getall") {
	$result = getTypeNews();
	echo json_encode($result);
} else if($action == 'remove') {
	if(isset($_POST['idpe'])) {
		echo json_encode(removeTypeNew($_POST['idpe']));
	}
}
?>